/**
 * 测试经理许可证路由
 *
 * Created by yangyunze on 2021/08/25.
 */
const middleware = require('./../middleware');
const licenseModel = require('./../../models/license');
const { fixLicenseStatusResponse } = require('../../helpers/licenseHelper');

/**
 * 获取许可证信息
 * @param req
 * @param res
 * @param next
 */
function getLicenseStatus(req, res, next) { // eslint-disable-line no-unused-vars
  fixLicenseStatusResponse(licenseModel.getLicenseStatusJson(req.$license))
    .then((license) => res.json(license));
}

/**
 * Export model definition object.
 */
module.exports = (app, prefix) => {
  const licenseStatusURL = `${prefix}/license/status.json`;

  // 获取许可证状态
  app.get(licenseStatusURL, middleware.user.requireTokenUnexpired);
  app.get(licenseStatusURL, middleware.user.requireAvailable);
  app.get(licenseStatusURL, middleware.user.requireTestManager);
  app.get(licenseStatusURL, middleware.license.requireLicenseExist);
  app.get(licenseStatusURL, getLicenseStatus);
};
